(function() {
  $(function() {
    var form;
    form = $('form.main');
    form.form({
      inline: true,
      fields: {
        merch_type: {
          optional: false,
          rules: [
            {
              type: 'empty'
            }
          ]
        },
        wizard_uuid: {
          optional: false,
          rules: [
            {
              type: 'empty'
            }
          ]
        }
      }
    });
    form.find('.dropdown.merch_type').dropdown({
      onChange: function(value, text, $choice) {
        $(this).addClass('loading');
        return $.post('/wizcheck/ajax/wizard_uuids', {
          merch_type: value
        }, function(resp) {
          var items, record, _i, _len, _ref;
          form.find('.dropdown.merch_type').removeClass('loading');
          form.find('.dropdown.wizard_uuid').dropdown('clear');
          if (!resp.succ) {
            form.find('.dropdown.wizard_uuid .menu').html('');
            return;
          }
          items = '';
          _ref = resp.records;
          for (_i = 0, _len = _ref.length; _i < _len; _i++) {
            record = _ref[_i];
            items += "<div class='item' data-value='" + record.uuid + "'>";
            items += "" + record.merno;
            items += "<div class='right floated' style='font-size:small; color:#888;'>" + record.mername;
            items += " ｜ " + record.termid;
            items += "</div>";
            items += "</div>";
          }
          form.find('.dropdown.wizard_uuid .menu').html(items);
          return form.find('.dropdown.wizard_uuid').dropdown('refresh');
        });
      }
    });
    return form.submit(function(evt) {
      var merch_type;
      if (!form.form('is valid')) {
        return;
      }
      merch_type = form.form('get value', 'merch_type');
      return form.attr('action', "/wizcheck/" + merch_type);
    });
  });

}).call(this);
